package com.jlastu.dlxy_androidapp.view.sell;

import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;

import com.jlastu.dlxy_androidapp.R;
import com.jlastu.dlxy_androidapp.view.main.AddSchoolActivity;
import com.jlastu.dlxy_androidapp.view.main.LandscapeActivity;
import com.jlastu.dlxy_androidapp.view.main.SchoolFragment;

public class MorenewsActivity extends AppCompatActivity {

    private SchoolFragment mSchoolFragment;
    private FragmentManager mFragmentManager;
    private Fragment mFragment;

    private TextView mTextAdd;
    @Override
    public void onConfigurationChanged(android.content.res.Configuration newConfig) {
        super.onConfigurationChanged(newConfig);

        // 检查屏幕方向是否为横屏
        if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
            Log.d("Orientation", "Landscape detected");

            // 创建并启动新的Activity
            Intent intent = new Intent(this, LandscapeActivity.class);
            startActivity(intent);

            // 可选：关闭当前Activity
            finish();
        }
    }
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_morenews);
        initFragment();
        mTextAdd = findViewById(R.id.add_morenews);
        mFragmentManager.beginTransaction().replace(R.id.fragment_morenews,mSchoolFragment).commitAllowingStateLoss();

        mTextAdd.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MorenewsActivity.this, AddSchoolActivity.class);
                startActivity(intent);
                Log.d("TAG", "onClick: 点击");
            }
        });
    }

    private void initFragment(){
        mFragmentManager = getSupportFragmentManager();
        mSchoolFragment = new SchoolFragment();

    }
}
